package se.energimyndigheten.lampguiden.util;

import android.content.Context;
import android.os.Build;
import android.webkit.WebView;

/* Helper super class for special compatibility checks over android versions */
public abstract class Compat {
    public abstract boolean isAccessibilityEnabled(Context ctx);

    public abstract void enableJavaScript(WebView wv);

    private static Compat sInstance;
    private static String myName = Compat.class.getName();

    // We intentionally use depreciated info since we want backwards compatibility
    @SuppressWarnings("deprecation")
    public static Compat getInstance() {
        if (sInstance == null) {
            String className;
            int sdkVersion = Integer.parseInt(Build.VERSION.SDK);
            if (sdkVersion < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                className = myName + "PreICS";
            } else {
                className = myName + "ICS";
            }
            try {
                Class<? extends Compat> clazz =
                        Class.forName(className).asSubclass(Compat.class);

                sInstance = clazz.newInstance();
            } catch (Exception e) {
                throw new IllegalStateException(e);
            }
        }
        return sInstance;
    }
}